IMBROGLIO ABSCISSATRON 1.0 - THE CUBIC FORMULA
----------------------------------------------

Below is the most commonly used formula for solving the
general cubic (third-order) equation.

1. Original cubic equation in general form:
	ax^3 + bx^2 + cx + d = 0

2. Calculate p and q:
	p = (3*c/a - (b/a)^2)/3
	q = (2*(b/a)^3 - 9*b*c/a/a + 27*d/a)/27

3. Calculate the discriminant D:
	D = (p/3)^3 + (q/2)^2

4. Depending on the value of D, you follow a different strategy:
	If D<0, three distinct real roots
	If D=0, three real roots of which at least two are equal
	If D>0, one real and two complex roots

	a) For D>0 and D=0:
		Calculate u and v:
		u = cbrt(-q/2 + sqrt(D))
		v = cbrt(-q/2 - sqrt(D))
	
		Find the three transformed roots:
		y1 = u + v
		y2 = -(u+v)/2 + i (u-v)*sqrt(3)/2
		y3 = -(u+v)/2 - i (u-v)*sqrt(3)/2

	b) Alternately, for D<0, a trigonometric formula is more convenient:
		t = acos(-q/2/sqrt(|p|^3/27))
		pi  = 3.1415926535897932384626433832795...

		y1 =  2 * sqrt(|p|/3) * cos(t/3)
		y2 = -2 * sqrt(|p|/3) * cos((t+pi)/3)
		y3 = -2 * sqrt(|p|/3) * cos((t-pi)/3)

		There is reason for why a trigonometric formula is used in this case.
		If it is not used, the other method produces complex number expressions
		that are nearly impossible to solve by hand.

5. Finally, find the three roots:
	x1 = y1 - b/a/3
	x2 = y2 - b/a/3
	x3 = y3 - b/a/3

-------------------------------
Copyright 2000 - Imbroglio Inc.